#! /bin/bash
export LANG=zh_CN.UTF-8
PRESTO_HOME=/export/server/presto/bin/presto


${PRESTO_HOME} --catalog hive --server 192.168.88.80:8090 --execute "
-- 打卡表数据插入
delete from hive.edu_dwd.hkl_fact_student_signin where 1=1;
insert into hive.edu_dwd.hkl_fact_student_signin
select
        id,
        normal_class_flag,
        time_table_id,
        class_id,
        student_id,
        signin_time,
        signin_date,
        inner_flag,
        signin_type,
        share_state,
        inner_ip
from hive.edu_ods.tbh_student_signin_record;

-- 学生请假表数据插入
delete from hive.edu_dwd.hkl_fact_student_leave where 1=1;
insert into hive.edu_dwd.hkl_fact_student_leave
select
        id,
        class_id,
        student_id,
        audit_state,
        audit_person,
        audit_time,
        audit_remark,
        leave_type,
        leave_reason,
        begin_time,
        begin_time_type,
        end_time,
        end_time_type,
        days,
        cancel_state,
        cancel_time,
        old_leave_id,
        leave_remark,
        valid_state,
        create_time
from hive.edu_ods.student_leave_apply
where class_id is not null and  audit_state in (0,1) and leave_type=1 and cancel_state=0 and valid_state=1;


-- 班级排课表数据插入
delete from hive.edu_dwd.hkl_dim_course_upload where 1=1;
insert into hive.edu_dwd.hkl_dim_course_upload
select
        id,
        base_id,
        class_id,
        class_date,
        content,
        teacher_id,
        teacher_name,
        job_number,
        classroom_id,
        classroom_name,
        is_outline,
        class_mode,
        is_stage_exam,
        is_pay,
        tutor_teacher_id,
        tutor_teacher_name,
        tutor_job_number,
        is_subsidy,
        answer_teacher_id,
        answer_teacher_name,
        answer_job_number,
        remark,
        create_time
from hive.edu_ods.course_table_upload_detail
where content <>'' and content <>'开班典礼' and content is not null and class_id is not null and cast(class_id as varchar(20)) <>'' ;


--班级作息信息表
delete from  hive.edu_dwd.hkl_dim_class_time where 1=1;
insert into hive.edu_dwd.hkl_dim_class_time
select
        id,
        class_id,
        morning_template_id,
        morning_begin_time,
        morning_end_time,
        afternoon_template_id,
        afternoon_begin_time,
        afternoon_end_time,
        evening_template_id,
        evening_begin_time,
        evening_end_time,
        use_begin_date,
        use_end_date,
        create_time,
        create_person,
        remark
from hive.edu_ods.tbh_class_time_table;

-- 在读学员人数信息表
delete from hive.edu_dwd.hkl_dim_studying_student;
insert into hive.edu_dwd.hkl_dim_studying_student
select
        id,
        school_id,
        subject_id,
        class_id,
        studying_student_count,
        studying_date
from hive.edu_ods.class_studying_student_count;"

